/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChequearDatos.java
 *
 * Created on 10-ene-2013, 18:51:41
 */
package gui;

import com.sun.awt.AWTUtilities;
import controladores.ControladorPrincipal;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import javax.swing.ImageIcon;
import utilidades.JFrameConFondo;

/**
 *
 * @author NiCo
 */
public class ChequearDatos extends JFrameConFondo {

    private final char donde;
    private Image icono = new ImageIcon(getClass().getResource("/imagenes/logo.png")).getImage();
    private MensajesConf p2;
    private MensajesConf p4;
    private char valor;

    /** Creates new form ChequearDatos */
    public ChequearDatos(char donde) {
        initComponents();
        this.donde = donde;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btnCerrar = new javax.swing.JButton();
        btnVerificar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellido = new javax.swing.JTextField();
        txtDni = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        btnContinuar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/titulo-chequear-datos.png"))); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png"))); // NOI18N
        btnCerrar.setBorder(null);
        btnCerrar.setBorderPainted(false);
        btnCerrar.setFocusPainted(false);
        btnCerrar.setName("btnCerrar"); // NOI18N
        btnCerrar.setOpaque(false);
        btnCerrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btnCerrarMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btnCerrarMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnCerrarMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btnCerrarMouseReleased(evt);
            }
        });
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        btnVerificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/verificar-datos.png"))); // NOI18N
        btnVerificar.setBorderPainted(false);
        btnVerificar.setFocusPainted(false);
        btnVerificar.setName("btnVerificar"); // NOI18N
        btnVerificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerificarActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Nombre del niño/adolescente");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Apellido del niño/adolscente");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("DNI del niño/adolescente");
        jLabel4.setName("jLabel4"); // NOI18N

        txtNombre.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtNombre.setName("txtNombre"); // NOI18N

        txtApellido.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtApellido.setName("txtApellido"); // NOI18N

        txtDni.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtDni.setName("txtDni"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("<html> NOTA: Si no conoce ninguno de los datos anteriores o tiene duda sobre los mismos, presione el botón “Continuar”"); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        btnContinuar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/continuar.png"))); // NOI18N
        btnContinuar.setBorderPainted(false);
        btnContinuar.setFocusPainted(false);
        btnContinuar.setName("btnContinuar"); // NOI18N
        btnContinuar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnContinuarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addComponent(btnCerrar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                            .addComponent(txtApellido)
                            .addComponent(txtDni, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(btnVerificar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnContinuar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCerrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtDni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnVerificar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnContinuar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseEntered

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-activo.png")));     }//GEN-LAST:event_btnCerrarMouseEntered

    private void btnCerrarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseExited

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png")));     }//GEN-LAST:event_btnCerrarMouseExited

    private void btnCerrarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMousePressed

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-click.png")));     }//GEN-LAST:event_btnCerrarMousePressed

    private void btnCerrarMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseReleased

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png")));     }//GEN-LAST:event_btnCerrarMouseReleased

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void btnVerificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerificarActionPerformed
        if (txtDni.getText().equals("")) {
            valor = ControladorPrincipal.getInstance().getControladorCasos().verificar_datos(txtNombre.getText(), txtApellido.getText(), (long) 0);
        } else {
            valor = ControladorPrincipal.getInstance().getControladorCasos().verificar_datos(txtNombre.getText(), txtApellido.getText(), Long.parseLong(txtDni.getText()));
        }
        switch (donde) {
            case 'n':
                switch (valor) {
                    case 'n':
                        long dni;
                        if (txtDni.getText().equals("")) {
                            dni = (long) 0;
                        } else {
                            dni = Long.parseLong(txtDni.getText());
                        }
                        NuevoCaso p1 = new NuevoCaso(txtNombre.getText(), txtApellido.getText(), dni, valor, null);
                        p1.setLocationRelativeTo(null);
                        p1.setIconImage(icono);
                        p1.setVisible(true);
                        Shape shape = new RoundRectangle2D.Float(0, 0, p1.getWidth(), p1.getHeight(), 30, 30);
                        AWTUtilities.setWindowShape(p1, shape);
                        this.dispose();
                        break;
                    case 'a':
                        p2 = new MensajesConf("NinoExisteCaso", this);
                        p2.setLocationRelativeTo(null);
                        p2.setIconImage(icono);
                        p2.setVisible(true);
                        shape = new RoundRectangle2D.Float(0, 0, p2.getWidth(), p2.getHeight(), 30, 30);
                        AWTUtilities.setWindowShape(p2, shape);
                        break;
                    case 'c':
                        if (txtDni.getText().equals("")) {
                            dni = (long) 0;
                        } else {
                            dni = Long.parseLong(txtDni.getText());
                        }
                        p1 = new NuevoCaso(txtNombre.getText(), txtApellido.getText(), dni, valor, null);
                        p1.setLocationRelativeTo(null);
                        p1.setIconImage(icono);
                        p1.setVisible(true);
                        shape = new RoundRectangle2D.Float(0, 0, p1.getWidth(), p1.getHeight(), 30, 30);
                        AWTUtilities.setWindowShape(p1, shape);
                        this.dispose();
                        break;
                    case 'd':
                        VerificarMasDeUnNinio p5 = new VerificarMasDeUnNinio(txtNombre.getText(), txtApellido.getText(),'n');
                        p5.setLocationRelativeTo(null);
                        p5.setIconImage(icono);
                        p5.setVisible(true);
                        shape = new RoundRectangle2D.Float(0, 0, p5.getWidth(), p5.getHeight(), 30, 30);
                        AWTUtilities.setWindowShape(p5, shape);
                        this.dispose();
                        break;
                }
                break;
            case 'a':
                
                break;
        }
    }//GEN-LAST:event_btnVerificarActionPerformed

    private void btnContinuarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnContinuarActionPerformed
        switch (donde) {
            case 'n':
                NuevoCaso p1 = new NuevoCaso("", "", (long) 0, 'n', null);
                p1.setLocationRelativeTo(null);
                p1.setIconImage(icono);
                p1.setVisible(true);
                Shape shape = new RoundRectangle2D.Float(0, 0, p1.getWidth(), p1.getHeight(), 30, 30);
                AWTUtilities.setWindowShape(p1, shape);
                this.dispose();
                break;
            case 'a':
                NuevaActualizacion p5 = new NuevaActualizacion();
                p5.setLocationRelativeTo(null);
                p5.setIconImage(icono);
                p5.setVisible(true);
                shape = new RoundRectangle2D.Float(0, 0, p5.getWidth(), p5.getHeight(), 30, 30);
                AWTUtilities.setWindowShape(p5, shape);
                this.dispose();
                break;
        }
    }//GEN-LAST:event_btnContinuarActionPerformed

    public void continuarNuevo() {
        long dni;
        if (!p2.isConfirmacion()) {
            if (txtDni.getText().equals("")) {
                dni = (long) 0;
            } else {
                dni = Long.parseLong(txtDni.getText());
            }
            NuevoCaso p1 = new NuevoCaso(txtNombre.getText(), txtApellido.getText(), dni, valor, null);
            p1.setLocationRelativeTo(null);
            p1.setIconImage(icono);
            p1.setVisible(true);
            Shape shape = new RoundRectangle2D.Float(0, 0, p1.getWidth(), p1.getHeight(), 30, 30);
            AWTUtilities.setWindowShape(p1, shape);
            this.dispose();
        } else {
            NuevaActualizacion p3 = new NuevaActualizacion();
            p3.setLocationRelativeTo(null);
            p3.setIconImage(icono);
            p3.setVisible(true);
            Shape shape = new RoundRectangle2D.Float(0, 0, p3.getWidth(), p3.getHeight(), 30, 30);
            AWTUtilities.setWindowShape(p3, shape);
            this.dispose();
        }
    }

    public void continuarActualizacion() {
        long dni;
        if (p4.isConfirmacion()) {
            if (txtDni.getText().equals("")) {
                dni = (long) 0;
            } else {
                dni = Long.parseLong(txtDni.getText());
            }
            NuevoCaso p3 = new NuevoCaso(txtNombre.getText(), txtApellido.getText(), dni, valor, null);
            p3.setLocationRelativeTo(null);
            p3.setIconImage(icono);
            p3.setVisible(true);
            Shape shape = new RoundRectangle2D.Float(0, 0, p3.getWidth(), p3.getHeight(), 30, 30);
            AWTUtilities.setWindowShape(p3, shape);
            this.dispose();
        } else {
            NuevaActualizacion p5 = new NuevaActualizacion();
            p5.setLocationRelativeTo(null);
            p5.setIconImage(icono);
            p5.setVisible(true);
            Shape shape = new RoundRectangle2D.Float(0, 0, p5.getWidth(), p5.getHeight(), 30, 30);
            AWTUtilities.setWindowShape(p5, shape);
            this.dispose();
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnContinuar;
    private javax.swing.JButton btnVerificar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtDni;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables
}
